/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__task_mng_list_node_show.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/18 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frlog.h"
#include "frmem.h"
#include "frlist.h"
#include "conntrack.h"
#include "frame.h"
#include "frtask_mng.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

void __task_mng_list_node_show(Frlist_node* node, char *p_outbuff, unsigned int ui_buff_size);

static void case1(void)
{
    Frlist_node *p_st_node = NULL;
    Conntrack *p_st_ct = NULL;
    char *p_outbuff = NULL;
    unsigned int ui_buff_size = 1024;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    p_st_ct->refcnt = 2;

    p_st_node = frlist_node_create(p_st_ct);

    p_outbuff = (char *)frmalloc(ui_buff_size);
    memset(p_outbuff,'\0',ui_buff_size);

    __task_mng_list_node_show(p_st_node, p_outbuff, ui_buff_size);

    CU_ASSERT_TRUE(memcmp(p_outbuff,"\0",ui_buff_size) != 0);
    frdbg("\t%s\n",p_outbuff);

    frfree(p_st_ct);
    frfree(p_st_node);
    frfree(p_outbuff);

    return;

}

static void case2(void)
{
    Frlist_node *p_st_node = NULL;
    Conntrack *p_st_ct = NULL;
    char *p_outbuff = NULL;
    unsigned int ui_buff_size = 0;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    p_st_ct->refcnt = 2;

    p_st_node = frlist_node_create(p_st_ct);

    __task_mng_list_node_show(p_st_node, p_outbuff, ui_buff_size);

    CU_ASSERT_PTR_NULL(p_outbuff);

    frfree(p_st_ct);
    frfree(p_st_node);

    return;

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__task_mng_list_node_show 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}